'use strict';
const {getDefaultModelConfig} = require("../../utils/common");
const {formatDecimal} = require("../../utils");

module.exports = app => {
    const { STRING, INTEGER, DATE, TINYINT, TEXT, DECIMAL } = app.Sequelize;
    const TicketLine = app.model.define(
        'TicketLine',
        {
            id: {type: INTEGER, primaryKey: true, autoIncrement: true},
            ticket_shop_id: INTEGER,
            product_category_id: INTEGER,
            title: STRING(255),
            unit: STRING(255),
            tags: TEXT,
            tags2: TEXT,
            dates: TEXT,
            description: STRING(255),
            content: TEXT,
            post_url: STRING(255),
            image_urls: TEXT,
            is_hot: {type: TINYINT, defaultValue: 0},
            is_recommend: {type: TINYINT, defaultValue: 0},
            virtual_sale_count: {type: INTEGER, defaultValue: 0},
            sale_count: {type: INTEGER, defaultValue: 0},
            price: {
                type: DECIMAL(10, 2), defaultValue: 0.00,
                get() {
                    return formatDecimal(this.getDataValue('price'))
                },
            },
            original_price: {
                type: DECIMAL(10, 2), defaultValue: 0.00,
                get() {
                    return formatDecimal(this.getDataValue('original_price'))
                },
            },
            // 库存
            stock: {type: INTEGER, defaultValue: 0},
            sort: {type: INTEGER, defaultValue: 0},
            status: {type: TINYINT, defaultValue: 1},
            ...getDefaultModelConfig(app)
        },
        {
            tableName: 'ticket_line',
            timestamps: true,
            createdAt: 'create_time',
            updatedAt: 'update_time'
        }
    );
    return TicketLine
};
